package com.uab.ia.entidades;

import com.android.dataframework.Entity;

public class Estacion {

	private long id;
	String nombre;
	String linea;
	int x;
	int y;
	private final static String table = "estacion";

	public Estacion(long id) {
		fromEntity(new Entity(table, id));
	}

	public Estacion(Entity ent) {
		fromEntity(ent);
	}

	private void fromEntity(Entity ent) {
		try {
			this.setId(ent.getId());
			this.nombre = ent.toString();
			this.linea = ent.getString("linea");

			this.x = ent.getInt("x");
			this.y = ent.getInt("y");
		} catch (Exception e) {

		}
	}

	public Estacion(String nombre, String linea, int x, int y) {
		this.nombre = nombre;
		this.linea = linea;
		this.x = x;
		this.y = y;
	}

	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public String getLinea() {
		return linea;
	}

	public void setLinea(String linea) {
		this.linea = linea;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public void save() {
		Entity ent;
		if (this.getId() != -1) {
			ent = new Entity(table, this.getId());
		} else {
			ent = new Entity(table);
			this.setId(ent.getId());
		}

		ent.setValue("nombre", this.nombre);
		ent.setValue("linea", linea);
		ent.setValue("x", x);
		ent.setValue("y", y);
		ent.save();
	}
}